<template>
  <view class="community">
    <view class="search">
      <view class="input" @tap="searchClick()">
        <image
          class="img"
          src="https://www.123qifu.com/onlineimages/static/Shopping/sous.png"
          mode=""
        />
        <input type="text" placeholder="请输入关键字搜索" />
      </view>
      <view class="tabs">
        <view
          :class="{ active: currentIndex === index }"
          v-for="(item, index) in itemList"
          :key="index"
          @click="topicClick(index)"
          >{{ item.title }}</view
        >
      </view>
    </view>
    <view class="secOne" v-show="currentIndex === 0">
      <view
        class="sec1"
        v-for="(content, index) in ConversationList"
        :key="index"
      >
        <view class="top">
          <view class="lef">
            <image
              class="avtar"
              :src="img + content.cover_image"
              mode="aspectFit"
            />
            <view class="huat">
              <view class="ht1"> <span>#</span>{{ content.title }}</view>
              <view class="ht2">
                <image
                  class="cyic"
                  src="https://www.123qifu.com/onlineimages/static/canyIcon.png"
                  mode=""
                />{{ content.joinNum }}人参与
              </view>
            </view>
          </view>
          <view class="rig" @click="join(content, content.id, content.title)"
            >加入</view
          >
        </view>
        <view class="text">{{ content.content }}</view>
        <view class="imglis">
          <image
            v-for="(item, indexs) in content.images"
            v-if="item.length == 0 ? false : true"
            :key="indexs"
            class="imgls"
            :src="img + item"
            mode="aspectFill"
            @click="picClcik(content.images, indexs)"
          />
        </view>
      </view>
    </view>
    <view class="secTwo" v-show="currentIndex === 1">
      <view class="lis" v-for="(gambit, index) in CareArticleList" :key="index">
        <view class="top">
          <image class="avtar" :src="gambit.user_avatar" mode="aspectFit" />
          <view class="rig">
            <view class="name">{{ gambit.user_nickname }}</view>
            <view class="tiem">{{ gambit.createtime | formatDate }}</view>
          </view>
        </view>
        <view class="tetx">
          <view
            class="tag"
            @click="join(gambit, gambit.topic_id, gambit.topicTitle)"
          >
            <span>#</span>{{ gambit.topicTitle }}
          </view>
          {{ gambit.content }}
        </view>
        <view class="imglis">
          <image
            v-for="(item, indexs) in gambit.images"
            v-if="item.length == 0 ? false : true"
            :key="indexs"
            class="imgls"
            :src="img + item"
            mode="aspectFill"
            @click="picClcik(gambit.images, indexs)"
          />
        </view>
      </view>
      <view class="friends" v-if="CareArticleList.length == 0"
        >您暂时还没有关注哦~</view
      >
    </view>
    <view class="secThree" v-show="currentIndex === 2">
      <image
        src="https://www.123qifu.com/onlineimages/static/issue.png"
        class="issueImg"
        mode="widthFix"
        @click="issueClick"
      ></image>
      <text>可在此发表您的想法</text>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      itemList: [
        {
          title: "话题",
        },
        {
          title: "关注",
        },
        {
          title: "发布",
        },
      ],
      currentIndex: 0, //关注
      ConversationList: [],
      CareArticleList: [],
      img: "https://www.123qifu.com/",
    };
  },
  onShow() {
    this.getconversationList();
    this.getCareArticle();
  },
  methods: {
    //搜索页
    searchClick() {
      uni.navigateTo({
        url: "../Search/Search",
      });
    },
    //tab 关注话题
    topicClick(index) {
      this.currentIndex = index;
    },
    // 加入话题
    join(item, id, title) {
      uni.setStorage({
        key: "topicDetail",
        data: item,
      });
      uni.navigateTo({
        url: "../Supplication/Supplication?id=" + id + "&title=" + title,
      });
    },
    //发布
    issueClick() {
      uni.navigateTo({
        url: "../Issue/Issue",
      });
    },
    //图片预览
    picClcik(item, index) {
      let that = this;
      let imgsArray = [];
      for (let i = 0; i < item.length; i++) {
        imgsArray.push(that.$IMG_URL + item[i]);
      }

      uni.previewImage({
        urls: imgsArray,
        current: imgsArray[index],
      });
    },
    // 获取话题列表
    async getconversationList() {
      let that = this;

      const res = await that.$myRequest({
        url: "index/getTopic",
        method: "POST",
        data: {},
      });

      if (res.data.code == 1) {
        this.ConversationList = res.data.data.data;
      } else {
        uni.showToast({
          title: res.data.msg,
          icon: "none",
        });
      }
    },
    // 获取关注的人文章列表
    async getCareArticle() {
      let that = this;
      const res = await that.$myRequest({
        url: "index/getCareArticle",
        method: "POST",
        data: {},
      });
      that.CareArticleList = res.data.data.data;
    },
  },
};
</script>

<style lang="scss" scoped>
page {
  width: 750rpx;
  background-color: #f4f4f4;
}
.community {
  min-height: 100vh;
  background-color: #f4f4f4;
  .search {
    width: 100%;
    height: 192rpx;
    overflow: hidden;
    background: #fff;
    box-sizing: border-box;
    padding: 10rpx 18rpx;
    .input {
      width: 100%;
      height: 64rpx;
      background: #f4f4f4;
      border-radius: 32rpx;
      display: flex;
      align-items: center;
      box-sizing: border-box;
      padding: 0 30rpx;
      .img {
        display: block;
        width: 32rpx;
        height: 32rpx;
        margin-right: 22rpx;
      }
      input {
        flex: 1;
        background: none;
        border: none;
        font-size: 28rpx;
        font-weight: 400;
        color: #999999;
      }
    }
  }
  .tabs {
    display: flex;
    align-items: center;
    box-sizing: border-box;
    padding: 0 13rpx;
    margin-top: 45rpx;
    view {
      font-size: 34rpx;
      font-weight: 400;
      color: #999999;
      margin-right: 50rpx;
      position: relative;
      &.active {
        color: #333333;
        font-weight: 550;
      }
      &.active::after {
        position: absolute;
        content: "";
        width: 48rpx;
        height: 6rpx;
        background: #c52b2e;
        border-radius: 50rpx;
        left: 50%;
        transform: translateX(-50%);
        bottom: -30rpx;
      }
    }
  }
  .secOne {
    .sec1 {
      margin-top: 20rpx;
      width: 100%;
      min-height: 200rpx;
      background: #fff;
      box-sizing: border-box;
      padding: 30rpx;
      overflow: hidden;
      .top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        .lef {
          display: flex;
          align-items: center;
          .avtar {
            display: block;
            width: 90rpx;
            height: 90rpx;
            margin-right: 25rpx;
          }
          .huat {
            display: flex;
            flex-wrap: wrap;
            flex-direction: column;
            justify-content: space-between;
            .ht1,
            .ht2 {
              display: flex;
              align-items: center;
              span {
                display: block;
                font-size: 30rpx;
                color: #c52b2e;
                margin-right: 15rpx;
              }
            }
            .ht1 {
              font-size: 30rpx;
              font-weight: 550;
              color: #373737;
            }
            .ht2 {
              .cyic {
                display: block;
                width: 18rpx;
                height: 18rpx;
                margin-right: 15rpx;
              }
              font-size: 20rpx;
              font-weight: 400;
              color: #999999;
            }
          }
        }
        .rig {
          width: 114rpx;
          height: 50rpx;
          border: 1rpx solid #c52b2e;
          border-radius: 50rpx;
          text-align: center;
          line-height: 50rpx;
          font-size: 30rpx;
          font-weight: 400;
          color: #c52b2e;
        }
      }
      .text {
        font-size: 28rpx;
        font-weight: 400;
        color: #333333;
        text-align: justify;
        margin-top: 25rpx;
      }
      .imglis {
        width: 105%;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        margin-top: 30rpx;
        .imgls {
          display: block;
          width: 220rpx;
          height: 220rpx;
          margin-right: 15rpx;
          margin-bottom: 15rpx;
          border-radius: 8rpx;
        }
      }
    }
  }
  .secTwo {
    width: 100%;
    min-height: calc(100vh - 280rpx);
    background: #fff;
    margin-top: 20rpx;
    box-sizing: border-box;
    padding: 0 24rpx;
    .lis {
      width: 100%;
      min-height: 200rpx;
      box-sizing: border-box;
      padding: 30rpx 0;
      border-bottom: 1rpx solid #eee;
      overflow: hidden;
      .top {
        display: flex;
        align-items: center;
        .avtar {
          display: block;
          width: 90rpx;
          height: 90rpx;
          border-radius: 50%;
          margin-right: 25rpx;
        }
        .rig {
          display: flex;
          flex-wrap: wrap;
          flex-direction: column;
          justify-content: center;
          .name {
            font-size: 30rpx;
            font-weight: 550;
            color: #333333;
          }
          .tiem {
            font-size: 20rpx;
            font-weight: 400;
            color: #999999;
          }
        }
      }
      .tetx {
        display: inline-block;
        margin-top: 25rpx;
        font-size: 28rpx;
        font-weight: 500;
        color: #333;
        line-height: 45rpx;
        text-align: justify;
        .tag {
          color: #303faf;
          display: inline-block;
          margin-right: 10rpx;
          white-space: nowrap;
          span {
            display: inline-block;
            margin-right: 5 rpx;
          }
        }
      }
      .imglis {
        width: 105%;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        margin-top: 25rpx;
        .imgls {
          display: block;
          width: 220rpx;
          height: 220rpx;
          margin-right: 15rpx;
          margin-bottom: 15rpx;
          border-radius: 8rpx;
        }
      }
    }
    .lis:last-child {
      border-bottom: none;
    }
    .friends {
      color: #7e7b7b;
      font-size: 36rpx;
      display: flex;
      justify-content: center;
      padding-top: 200rpx;
    }
  }
  .secThree {
    width: 100%;
    min-height: calc(100vh - 280rpx);
    background: #fff;
    margin-top: 20rpx;
    box-sizing: border-box;
    padding: 0 24rpx;
    overflow: hidden;
    .issueImg {
      display: block;
      width: 210rpx;
      height: 210rpx;
      margin: 250rpx auto 0;
    }
    text {
      display: block;
      text-align: center;
      font-size: 30rpx;
      font-weight: 400;
      color: #999999;
      margin-top: 45rpx;
    }
  }
}
</style>
